package settingsapp.settings.continuous;

import settingsapp.ui.PanelGridActivity;
import android.util.Log;
import android.view.WindowManager.LayoutParams;
import ece.settingsapp.R;

public class SettingBrightness extends ContinuousSettingChanger
{
	public SettingBrightness(PanelGridActivity context, int intRepresentation)
	{
		super(context, intRepresentation);
		// max and min are in the documentation
		max = 255;
		min = 0;
	}
	
	protected void setIntValue(int value)
	{
		android.provider.Settings.System.putString(context.getContentResolver(),
				android.provider.Settings.System.SCREEN_BRIGHTNESS, Integer.toString(value));
		LayoutParams lp = context.getWindow().getAttributes();
		lp.screenBrightness = Math.max(getPercentage() / 100f, .05f);		// 0% turns the screen off, so have it be at at least 5%
		context.getWindow().setAttributes(lp);
	}

	@Override
	public void readValue()
	{
		Log.d("setting", "context == null? " + (context == null));
		String result = android.provider.Settings.System.getString(context.getContentResolver(),
				android.provider.Settings.System.SCREEN_BRIGHTNESS);
		Log.d("setting", "result is " + result);
		absoluteValue = Integer.parseInt(result);
	}

	@Override
	public int getIconResource()
	{
		return R.drawable.brightness;
	}
}
